package com.jt.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.jt.mapper.RightsMapper;
import com.jt.mapper.RoleRigthMapper;
import com.jt.pojo.Rights;
import com.jt.pojo.RoleRights;
import com.jt.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class RightsServiceImpl  implements  RightsService {

      @Autowired
      private RightsMapper  rightsMapper;

      @Autowired
      private RoleRigthMapper  roleRigthMapper;

    @Override
    public List<Rights> findRightsList() {
        //通过用户的角色进行判断获取哪些权限
//        QueryWrapper<RoleRights> queryWrapper = new QueryWrapper<>();
//        //queryWrapper.eq("role_id", 3);
//
//        List<RoleRights> roleRights = roleRigthMapper.selectList(queryWrapper);
//        List<Integer>  rights=new ArrayList<>();
//        for (RoleRights roleRight : roleRights) {
//            rights.add(roleRight.getRightsId());
//        }

        QueryWrapper<Rights> query = new QueryWrapper<>();
      //  query.in("id",rights.toArray());
        query.eq("parent_id",0);
        List<Rights> oneList = rightsMapper.selectList(query);


        //2.如何查询二级菜单  父子关系的封装!!!
        for (Rights oneRights : oneList) {
            //查询该元素的二级菜单
            //QueryWrapper<Rights> queryWrapper2 = new QueryWrapper<>();
            query.clear();
            query.eq("parent_id", oneRights.getId());
            List<Rights> twoList = rightsMapper.selectList(query);
            oneRights.setChildren(twoList);
        }

        return  oneList;
    }


}
